<html devsite>
  <head>
    <title>Install TensorFlow with pip</title>
    <meta name="project_path" value="/_project.yaml" />
    <meta name="book_path" value="/_book.yaml" />
    <link rel="stylesheet" href="/site-assets/css/style.css">
  </head>
  <body>

<h3>TensorFlow 2 packages are available</h3>
<ul>
  <li><code>tensorflow</code> —Latest stable release with CPU and <a href="./gpu">GPU support</a> <em>(Ubuntu and Windows)</em></li>
  <li><code>tf-nightly</code> —Preview build <em>(unstable)</em>. Ubuntu and Windows include <a href="./gpu">GPU support</a>. </li>
</ul>


<h3>Older versions of TensorFlow</h3>

<p>For TensorFlow 1.x, CPU and GPU packages are separate:</p>

<ul>
  <li><code>tensorflow==1.15</code> —Release for CPU-only</li>
  <li><code>tensorflow-gpu==1.15</code> —Release with <a href="./gpu">GPU support</a> <em>(Ubuntu and Windows)</em></li>
</ul>


<h3>System requirements</h3>
<ul>
  <li>Python 3.6–3.9
    <ul>
      <li>Python 3.9 support requires TensorFlow 2.5 or later.</li>
      <li>Python 3.8 support requires TensorFlow 2.2 or later.</li>
    </ul>
  </li>
  <li>pip 19.0 or later (requires <code>manylinux2010</code> support)</li>
  <li>Ubuntu 16.04 or later (64-bit)</li>
  <li>macOS 10.12.6 (Sierra) or later (64-bit) <em>(no GPU support)</em>
    <ul>
      <li>macOS requires pip 20.3 or later</li>
    </ul>
  </li>
  <li>Windows 7 or later (64-bit)
    <ul>
      <li><a href="https://support.microsoft.com/help/2977003/the-latest-supported-visual-c-downloads">Microsoft Visual C++
          Redistributable for Visual Studio 2015, 2017 and 2019</a></li>
    </ul>
  </li>
  <li><a href="./gpu">GPU support</a> requires a CUDA®-enabled card <em>(Ubuntu and Windows)</em></li>
</ul>

<aside class="note">
  <b>Note:</b> Installing TensorFlow 2 <em>requires</em> a newer version of <code>pip</code>.
</aside>

<h3>Hardware requirements</h3>
<ul>
  <li>Starting with TensorFlow 1.6, binaries use <a href="https://en.wikipedia.org/wiki/Advanced_Vector_Extensions#CPUs_with_AVX" class="external">AVX instructions</a> which may not run on older CPUs.</li>
  <li>Read the <a href="./gpu">GPU support guide</a> to set up a CUDA®-enabled GPU card on Ubuntu or Windows.</li>
</ul>


<h2>1. Install the Python development environment on your system</h2>

<p>
  Check if your Python environment is already configured:
</p>

<aside class="note">Requires Python 3.6–3.9, pip and venv &gt;= 19.0</aside>

<pre class="prettyprint lang-bsh">
<code class="devsite-terminal">python3 --version</code>
<code class="devsite-terminal">pip3 --version</code>
</pre>

<p>
  If these packages are already installed, skip to the next step.<br/>
  Otherwise, install <a href="https://www.python.org/" class="external">Python</a>, the
  <a href="https://pip.pypa.io/en/stable/installing/" class="external">pip package manager</a>,
  and <a href="https://docs.python.org/3/library/venv.html" class="external">venv</a>:
</p>

<div class="ds-selector-tabs">
<section>
<h3>Ubuntu</h3>
<pre class="prettyprint lang-bsh">
<code class="devsite-terminal">sudo apt update</code>
<code class="devsite-terminal">sudo apt install python3-dev python3-pip python3-venv</code>
</pre>
</section>

<section>
<h3>macOS</h3>
<p>Install using the <a href="https://brew.sh/" class="external">Homebrew</a> package manager:</p>
<pre class="prettyprint lang-bsh">
<code class="devsite-terminal">/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"</code>
<code class="devsite-terminal">export PATH="/usr/local/opt/python/libexec/bin:$PATH"</code>
<code class="devsite-terminal"># if you are on macOS 10.12 (Sierra) use `export PATH="/usr/local/bin:/usr/local/sbin:$PATH"`</code>
<code class="devsite-terminal">brew update</code>
<code class="devsite-terminal">brew install python  # Python 3</code>
</pre>
</section>

<section>
<h3>Windows</h3>
<p>
  Install the <em>Microsoft Visual C++ Redistributable for Visual Studio 2015, 2017,
  and 2019</em>. Starting with the TensorFlow 2.1.0 version, the <code>msvcp140_1.dll</code>
  file is required from this package (which may not be provided from older redistributable packages).
  The redistributable comes with <em>Visual Studio 2019</em> but can be installed separately:
</p>
<ol>
<li>Go to the <a href="https://support.microsoft.com/help/2977003/the-latest-supported-visual-c-downloads" class="external">Microsoft Visual C++ downloads</a>,</li>
<li>Scroll down the page to the <em>Visual Studio 2015, 2017 and 2019</em> section.</li>
<li>Download and install the <em>Microsoft Visual C++ Redistributable for Visual Studio 2015, 2017 and 2019</em> for your platform.</li>
</ol>
<p>Make sure <a href="https://superuser.com/questions/1119883/windows-10-enable-ntfs-long-paths-policy-option-missing" class="external">long paths are enabled</a> on Windows.</p>
<p>Install the <em>64-bit</em> <a href="https://www.python.org/downloads/windows/" class="external">Python 3 release for Windows</a> (select <code>pip</code> as an optional feature).</p>
</section>

<section>
<h3>Other</h3>
<pre class="prettyprint lang-bsh">
<code class="devsite-terminal">curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py</code>
<code class="devsite-terminal">python get-pip.py</code>
</pre>
</section>
</div><!--/ds-selector-tabs-->

<aside class="caution"><b>Caution:</b> Upgrading the <em>system pip</em> can cause
  <a href="https://github.com/pypa/pip/issues/5599" class="external">problems</a>.<br/>
  If <em>not</em> in a virtual environment, use <code>python3 -m pip</code> for
  the commands below. This ensures that you upgrade and use the
  <em>Python pip</em> instead of the <em>system pip</em>.
</aside>


<h2>2. Create a virtual environment (recommended)</h2>

<p>
  Python virtual environments are used to isolate package installation from the system.
</p>

<div class="ds-selector-tabs">
<section>
<h3>Ubuntu / macOS</h3>
<p>
  Create a new virtual environment by choosing a Python interpreter and making a
  <code>./venv</code> directory to hold it:
</p>
<pre class="devsite-terminal devsite-click-to-copy">python3 -m venv --system-site-packages <var>./venv</var></pre>
<p>
  Activate the virtual environment using a shell-specific command:
</p>
<pre class="devsite-terminal prettyprint lang-bsh">source <var>./venv</var>/bin/activate  # sh, bash, or zsh</pre>
<pre class="devsite-terminal prettyprint lang-bsh">. <var>./venv</var>/bin/activate.fish  # fish</pre>
<pre class="devsite-terminal prettyprint lang-bsh">source <var>./venv</var>/bin/activate.csh  # csh or tcsh</pre>

<p>
  When the virtual environment is active, your shell prompt is prefixed with <code>(venv)</code>.
</p>
<p>
  Install packages within a virtual environment without affecting the host system
  setup. Start by upgrading <code>pip</code>:
</p>
<pre class="prettyprint lang-bsh">
<code class="devsite-terminal tfo-terminal-venv">pip install --upgrade pip</code>

<code class="devsite-terminal tfo-terminal-venv">pip list  # show packages installed within the virtual environment</code>
</pre>
<p>
  And to exit the virtual environment later:
</p>
<pre class="devsite-terminal tfo-terminal-venv prettyprint lang-bsh">deactivate  # don't exit until you're done using TensorFlow</pre>
</section>


<section>
  <h3>Windows</h3>
  <p>
  Create a new virtual environment by choosing a Python interpreter and making a
  <code>.\venv</code> directory to hold it:
</p>
<pre class="devsite-terminal tfo-terminal-windows devsite-click-to-copy">python -m venv --system-site-packages <var>.\venv</var></pre>
<p>
  Activate the virtual environment:
</p>
<pre class="devsite-terminal tfo-terminal-windows-venv"><var>.\venv</var>\Scripts\activate</pre>
<p>
  Install packages within a virtual environment without affecting the host system
  setup. Start by upgrading <code>pip</code>:
</p>
<pre class="prettyprint lang-bsh">
<code class="devsite-terminal tfo-terminal-windows-venv">pip install --upgrade pip</code>

<code class="devsite-terminal tfo-terminal-windows-venv">pip list  # show packages installed within the virtual environment</code>
</pre>
<p>
  And to exit the virtual environment later:
</p>
<pre class="devsite-terminal tfo-terminal-windows-venv prettyprint lang-bsh">deactivate  # don't exit until you're done using TensorFlow</pre>
</section>


<section>
<h3>Conda</h3>
<p>
While the TensorFlow provided <em>pip</em> package is recommended, a
<em>community-supported</em> <a href="https://anaconda.org/anaconda/tensorflow" class="external">Anaconda package</a>
is available. To install, read the <a href="https://docs.anaconda.com/anaconda/user-guide/tasks/tensorflow/" class="external">Anaconda TensorFlow guide</a>.
</p>
</section>
</div><!--/ds-selector-tabs-->


<h2>3. Install the TensorFlow pip package</h2>

<p>
  Choose one of the following TensorFlow packages to install <a href="https://pypi.org/project/tensorflow/" class="external">from PyPI</a>:
</p>

<ul>
  <li><code>tensorflow</code> —Latest stable release with CPU and <a href="./gpu">GPU support</a> <em>(Ubuntu and Windows)</em>.</li>
  <li><code>tf-nightly</code> —Preview build <em>(unstable)</em>. Ubuntu and Windows include <a href="./gpu">GPU support</a>.</li>
  <li><code>tensorflow==1.15</code> —The final version of TensorFlow 1.x.</li>
</ul>

<aside class="note">
  Package dependencies are automatically installed. These are listed in the
  <a href="https://github.com/tensorflow/tensorflow/blob/master/tensorflow/tools/pip_package/setup.py" class="external"><code>setup.py</code></a>
  file under <code>REQUIRED_PACKAGES</code>.
</aside>

<div class="ds-selector-tabs">
<section>
<h3>Virtual environment install</h3>
<pre class="devsite-terminal tfo-terminal-venv devsite-click-to-copy prettyprint lang-bsh">pip install --upgrade tensorflow</pre>
<p>Verify the install:</p>
<pre class="devsite-terminal tfo-terminal-venv devsite-click-to-copy prettyprint lang-bsh">python -c "import tensorflow as tf;print(tf.reduce_sum(tf.random.normal([1000, 1000])))"</pre>
</section>

<section>
<h3>System install</h3>
<pre class="devsite-terminal devsite-click-to-copy prettyprint lang-bsh">pip3 install --user --upgrade tensorflow  # install in $HOME</pre>
<p>Verify the install:</p>
<pre class="devsite-terminal devsite-click-to-copy prettyprint lang-bsh">python3 -c "import tensorflow as tf; print(tf.reduce_sum(tf.random.normal([1000, 1000])))"</pre>
</section>
</div><!--/ds-selector-tabs-->

<aside class="success"><b>Success:</b> If a tensor is returned, you've installed TensorFlow successfully. Read the <a href="../tutorials">tutorials</a> to get started.</aside>

<h2>Package location</h2>

<p>
  A few installation mechanisms require the URL of the TensorFlow Python package.
  The value you specify depends on your Python version.
</p>


<table>
  <tr><th>Version</th><th>URL</th></tr>
  <tr class="alt"><td colspan="2">Linux</td></tr>
  <tr>
    <td>Python 3.6 GPU&nbsp;support</td>
    <td class="devsite-click-to-copy">https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-2.5.0-cp36-cp36m-manylinux2010_x86_64.whl</td>
  </tr>
  <tr>
    <td>Python 3.6 CPU-only</td>
    <td class="devsite-click-to-copy">https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow_cpu-2.5.0-cp36-cp36m-manylinux2010_x86_64.whl</td>
  </tr>
  <tr>
    <td>Python 3.7 GPU&nbsp;support</td>
    <td class="devsite-click-to-copy">https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-2.5.0-cp37-cp37m-manylinux2010_x86_64.whl</td>
  </tr>
  <tr>
    <td>Python 3.7 CPU-only</td>
    <td class="devsite-click-to-copy">https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow_cpu-2.5.0-cp37-cp37m-manylinux2010_x86_64.whl</td>
  </tr>
  <tr>
    <td>Python 3.8 GPU&nbsp;support</td>
    <td class="devsite-click-to-copy">https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-2.5.0-cp38-cp38-manylinux2010_x86_64.whl</td>
  </tr>
  <tr>
    <td>Python 3.8 CPU-only</td>
    <td class="devsite-click-to-copy">https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow_cpu-2.5.0-cp38-cp38-manylinux2010_x86_64.whl</td>
  </tr>
  <tr>
    <td>Python 3.9 GPU&nbsp;support</td>
    <td class="devsite-click-to-copy">https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-2.5.0-cp39-cp39-manylinux2010_x86_64.whl</td>
  </tr>
  <tr>
    <td>Python 3.9 CPU-only</td>
    <td class="devsite-click-to-copy">https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow_cpu-2.5.0-cp39-cp39-manylinux2010_x86_64.whl</td>
  </tr>

  <tr class="alt"><td colspan="2">macOS (CPU-only)</td></tr>
  <tr>
    <td>Python 3.6</td>
    <td class="devsite-click-to-copy">https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-2.5.0-cp36-cp36m-macosx_10_11_x86_64.whl</td>
  </tr>
  <tr>
    <td>Python 3.7</td>
    <td class="devsite-click-to-copy">https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-2.5.0-cp37-cp37m-macosx_10_11_x86_64.whl</td>
  </tr>
  <tr>
    <td>Python 3.8</td>
    <td class="devsite-click-to-copy">https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-2.5.0-cp38-cp38-macosx_10_11_x86_64.whl</td>
  </tr>
  <tr>
    <td>Python 3.8</td>
    <td class="devsite-click-to-copy">https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-2.5.0-cp39-cp39-macosx_10_11_x86_64.whl</td>
  </tr>

  <tr class="alt"><td colspan="2">Windows</td></tr>
  <tr>
    <td>Python 3.6 GPU&nbsp;support</td>
    <td class="devsite-click-to-copy">https://storage.googleapis.com/tensorflow/windows/gpu/tensorflow_gpu-2.5.0-cp36-cp36m-win_amd64.whl</td>
  </tr>
  <tr>
    <td>Python 3.6 CPU-only</td>
    <td class="devsite-click-to-copy">https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow_cpu-2.5.0-cp36-cp36m-win_amd64.whl</td>
  </tr>
  <tr>
    <td>Python 3.7 GPU&nbsp;support</td>
    <td class="devsite-click-to-copy">https://storage.googleapis.com/tensorflow/windows/gpu/tensorflow_gpu-2.5.0-cp37-cp37m-win_amd64.whl</td>
  </tr>
  <tr>
    <td>Python 3.7 CPU-only</td>
    <td class="devsite-click-to-copy">https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow_cpu-2.5.0-cp37-cp37m-win_amd64.whl</td>
  </tr>
  <tr>
    <td>Python 3.8 GPU&nbsp;support</td>
    <td class="devsite-click-to-copy">https://storage.googleapis.com/tensorflow/windows/gpu/tensorflow_gpu-2.5.0-cp38-cp38-win_amd64.whl</td>
  </tr>
  <tr>
    <td>Python 3.8 CPU-only</td>
    <td class="devsite-click-to-copy">https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow_cpu-2.5.0-cp38-cp38-win_amd64.whl</td>
  </tr>
  <tr>
    <td>Python 3.9 GPU&nbsp;support</td>
    <td class="devsite-click-to-copy">https://storage.googleapis.com/tensorflow/windows/gpu/tensorflow_gpu-2.5.0-cp39-cp39-win_amd64.whl</td>
  </tr>
  <tr>
    <td>Python 3.9 CPU-only</td>
    <td class="devsite-click-to-copy">https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow_cpu-2.5.0-cp39-cp39-win_amd64.whl</td>
  </tr>

</table>

</body>
</html>
